package com.ihisomp.controller;

import com.ihisomp.base.Result;
import com.ihisomp.dto.OrgRoleDto;
import com.ihisomp.service.IOrgRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 角色信息 前端控制器
 * </p>
 *
 * @author zy
 * @since 2022-04-12
 */
@RestController
@Api(value = "机构角色信息", tags = "机构角色信息")
@RequestMapping("/orgRole")
public class OrgRoleController {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private IOrgRoleService orgRoleService;

    /**
     * 分页查询
     *
     * @param page
     * @param size
     * @param orgRoleDto
     * @return
     */
    @PostMapping("/search/{page}/{size}")
    @ApiOperation("分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", required = true),
            @ApiImplicitParam(name = "size", value = "每页条数", required = true),
            @ApiImplicitParam(name = "orgRoleDto", value = "机构角色数据类", required = true)})
    public Result search(@PathVariable("page") long page,
                         @PathVariable("size") long size,
                         @RequestBody(required = false) OrgRoleDto orgRoleDto) {
        logger.info("分页查询：page={}，size={}, orgRoleDto={}", page, size, orgRoleDto);
        Result result = orgRoleService.search(page, size, orgRoleDto);
        return result;
    }

    /**
     * 新增数据
     *
     * @param orgRoleDto
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("新增数据")
    @ApiImplicitParam(name = "orgRoleDto", value = "机构角色数据类", required = true)
    public Result add(@RequestBody OrgRoleDto orgRoleDto) {
        logger.info("新增数据：orgRoleDto={}", orgRoleDto);
        Result result = orgRoleService.add(orgRoleDto);
        return result;
    }

    /**
     * 删除数据
     *
     * @param roleKey
     * @return
     */
    @GetMapping("/delete/{roleKey}")
    @ApiOperation("删除数据")
    @ApiImplicitParam(name = "roleKey", value = "机构角色主键", required = true)
    public Result delete(@PathVariable("roleKey") String roleKey) {
        logger.info("删除数据：roleKey={}", roleKey);
        Result result = orgRoleService.delete(roleKey);
        return result;
    }

    /**
     * 更新数据
     *
     * @param roleKey
     * @param orgRoleDto
     * @return
     */
    @PostMapping("/update/{roleKey}")
    @ApiOperation("更新数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleKey", value = "机构角色主键", required = true),
            @ApiImplicitParam(name = "orgRoleDto", value = "机构角色数据类", required = true)})
    public Result update(@PathVariable("roleKey") String roleKey, @RequestBody OrgRoleDto orgRoleDto) {
        logger.info("更新数据：roleKey={}， orgRoleDto={}", roleKey, orgRoleDto);
        Result result = orgRoleService.update(roleKey, orgRoleDto);
        return result;
    }

    /**
     * 查询数据
     *
     * @param roleKey
     * @return
     */
    @GetMapping("/get/{roleKey}")
    @ApiOperation("查询数据")
    @ApiImplicitParam(name = "roleKey", value = "机构角色主键", required = true)
    public Result get(@PathVariable("roleKey") String roleKey) {
        logger.info("查询数据：roleKey={}", roleKey);
        Result result = orgRoleService.get(roleKey);
        return result;
    }

    /**
     * 角色数据列表
     * @param orgRoleDto
     * @return
     */
    @PostMapping("/selectList")
    @ApiOperation("机构角色列表")
    @ApiImplicitParam(name = "orgRoleDto", value = "机构角色数据类", required = true)
    public Result selectList(@RequestBody OrgRoleDto orgRoleDto) {
        logger.info("角色数据列表");
        Result result = orgRoleService.selectList(orgRoleDto);
        return result;
    }

    /**
     * 更新角色权限
     *
     * @param roleKey
     * @param orgRoleDto
     * @return
     */
    @PostMapping("/updateRolePath/{roleKey}")
    @ApiOperation("更新角色权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleKey", value = "机构角色主键", required = true),
            @ApiImplicitParam(name = "orgRoleDto", value = "机构角色数据类", required = true)})
    public Result updateRolePath(@PathVariable("roleKey") String roleKey, @RequestBody OrgRoleDto orgRoleDto) {
        logger.info("更新角色权限：roleKey={}, orgRoleDto={}", roleKey, orgRoleDto);
        Result result = orgRoleService.updateRolePath(roleKey, orgRoleDto);
        return result;
    }

}
